//base salary
var base = 2000;

/**
 * range and tax-rage convert table
 */
var convertTable = {
	"0~1000" : 0.1,
	"1000~2000" : 0.15,
	"2000~3000" : 0.2,
	"3000~5000" : 0.25,
	"5000~8000" : 0.3,
	"8000~-1" : 0.4
}

/**
 * if the value is in the range?
 */
function inRange(value, range){
	var vs = range.split("~");
	var low, high;
	low = parseFloat(vs[0]);
	high = parseFloat(vs[1]);
	if(high == -1){//-1 means infinity
		high = Number.MAX_VALUE;
	}
	return (value >= low && value <= high);
}

/**
 * This is the function will be invoked by java program
 * @param salary
 * @return
 */
function calc(salary){
	var value;
	
	// less that or equals to base
	if(salary <= base){
		value = salary;
	}else{
		var f = salary - base;
		for(var item in convertTable){
			if(inRange(f, item)){
				value = salary - salary * convertTable[item];
				break;
			}
		}
	}
	
	return value;
}
